<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" >
	<meta name="author" content="wangyuguo">
	<title>单位销司机卡</title>
	<script language="javascript" src="../script/print.js" type="text/javascript"></script>
	<script language="javascript" src="../script/common.js" type="text/javascript"></script>
	<script language="javascript" src="../script/card.js" type="text/javascript"></script>
	<!--动态js-->
	<script language="javascript" type="text/javascript">
	//页面加载方法
	var qt;	
	var companyData;
	
	function load(){
		Eui.showNavigation();
		setPages(["mainview","readcardview","detview"]);
		CardMgnt.cardUser.show("companyUserView",null,CardMgnt.COMPANYUSER)
	}
	
	//读主卡，查找单位客户帐户
	function readMasterCard(){
		try{
			onCancel();
			getCard();
		}catch(e){showError(e.description);return;}
		var asn = getAsn();
		companyform.asn.value = asn;
		DWR.call("mgntQueryService.checkRevocateCompany",asn,null,showCompanyUser)
	}
	
	//通过客户编号查找单位客户帐户
	function findCompanyUser(){
		var uniqueId = companyform.uniqueId.value;
		try{
			if (!uniqueId)
				throw new Error("请输入或选择一个客户编号")
			var data = DWR.syncCall("mgntQueryService.checkRevocateCompany",null,uniqueId)
			showCompanyUser(data);
		}catch(e){
			showError(e.description);
			onCancel();
		}
	}
	
	//选择客户编号编号
	function selCardUser(){
		CardMgnt.selCardUser(function(v){
			companyform.uniqueId.value = v.uniqueId;
		},{cardUserType:CardUserType.COMPANY})
	}
	//显示单位客户信息
	function showCompanyUser(data){
		var companyUser = data.cardUser;
		if (companyUser.type != CardUserType.COMPANY){
			showWarning("不是单位帐户！");
			return;
		}
		CardMgnt.cardUser.showData("companyUserView",data,CardMgnt.COMPANYUSER)
		$("revocateCompanyBtn").disabled = false;
		companyData = data;
	}
	

	//销单位帐户方法
	function revocatCompany(){
		$("revocateCompanyBtn").disabled = false;
		var companyUser = companyData.cardUser;
		if (!companyData.lock){
			if (companyData.revDriver){
				if (showQuestion("单位存在未注销的司机帐户，是否先注销司机！")){
					switchPage("readcardview");
					var url = spellUrl("revocat_drivers_frame.html",{revocatCompany:true});
					releaseCard();
					revocatframe.document.location.href = url;
				}
			}else{
				DWR.call("cardMgntService.companyRevocation",companyUser.uniqueId,function(data){
					showInformation("单位销户成功！");
					switchPage("detview");
					CardMgnt.showPrintView("detview","kill_unit_bill",data.logId,"单位销户凭证");
					try{
						WebPrint.print("billview");
					}catch(e){
						showError("打印单据出错:"+e.description)
					}
				},{blockScreen:true});
			}
		}else{
			if (showQuestion("单位司机尚未完全冻结，是否做冻结？")){
				DWR.call("blacklistService.freezeCardUser",companyUser.uniqueId,function(){
					showInformation("司机冻结成功。<br>"+companyData.cardLostHours + "小时后，再做帐户注销！");
					onCancel();
				})
			}
		}
		
	}
	
	//注销司机结束后，返回注销单位页面
	function toRevocateCompany(){
		switchPage("mainview");
		$("revocateCompanyBtn").disabled = false;
	}
	
	//重置
	function onCancel(){
		switchPage("mainview");
		companyData = null;
		$("revocateCompanyBtn").disabled = true
		companyform.reset();
		$(CardMgnt.cardUser.formName).reset();
	}
	</script>
</head>
<body onload="load()">
	<!--页面导航-->
	<div class="nav"><div id="nav">&nbsp;</div></div>
	<div id="mainview">
		<div class="form">
			<form id="companyform" name="companyform">
				<div class="formTitle"><div class="l">查询单位客户</div><div class="r">
				</div></div>
				<table cellSpacing=0 cellPadding=4 width="100%" border=0 class="label6">
					<tr>
						<td>
							<label>单位主卡</label> <input type="text" name="asn" readonly class="readonly">
							<button onclick="readMasterCard()">读主卡</button>
						</td>
						<td>
							<label>客户编号</label> <input type="text" name="uniqueId"><a class="orga" href="#" onclick="selCardUser()">&nbsp;&nbsp;</a>
							<button onclick="findCompanyUser()">查 询</button>
						</td>
					</tr>	
				</table>
			</form>
		</div>
		
		<div id="companyUserView" class="form">
		</div>
		<p>
			<button onclick="revocatCompany()" id="revocateCompanyBtn" disabled>注销单位</button>
			<button onclick="onCancel()">重 置</button>
		</p>
	</div>
	<div id="readcardview" style="display:none;">
		<iframe id="revocatframe" name="revocatframe" style="width:100%;height:500px;overflow:hidden" scrolling="no" frameborder=0 src=""></iframe>
	</div>
	<!--凭证页面-->
	<div id="detview" style="display:none;">
	</div>
</body>
</html>